﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace NB_Controller_Test
{
    public partial class MainUIEx : UserControl
    {
        private void DoVerCheck(DevItemView devItem, ref UInt16 usVerMatchSize)
        {
            string strVerClasSkuInfo = devItem.ver.Text;
            string[] strInfos = strVerClasSkuInfo.Split('|');
            if (strInfos.Length >= 1)
            {
                if (strInfos[0] == tbOTABinFileVer.Text)
                {
                    usVerMatchSize++;
                    devItem.Background = sbVerOK;
                }
                else
                {
                    devItem.Background = sbVerError;
                }
            }
            else
            {
                if (devItem.ver.Text == tbOTABinFileVer.Text)
                {
                    usVerMatchSize++;
                    devItem.Background = sbVerOK;
                }
                else
                {
                    devItem.Background = sbVerError;
                }
            }
        }

        private void DoCheckOTAStatus(DevItemView devItem)
        {
            if (devItem.otaInfo.Tag != null)
            {
                //判断当前是否已经超时了，若超时了则主动置OTA失败，否则就主动询问OTA状态
                DateTime dateLastOTA = (DateTime)devItem.otaInfo.Tag;// as DateTime;
                if (dateLastOTA != null)
                {
                    //判断是否已经超时
                    TimeSpan timeSpan = DateTime.Now - dateLastOTA;
                    if (timeSpan.Seconds >= uiOTA_TimeOutTime)
                    {
                        //超时了
                        devItem.otaInfo.Text += " OTA超时";
                        devItem.otaInfo.Tag = null;
                        devItem.otaProgress.Visibility = System.Windows.Visibility.Collapsed;
                        devItem.otaInfo.Foreground = new SolidColorBrush(Colors.Orange);
                    }
                    else
                    {
                        //没超时
                        IntPtr intPtr = (IntPtr)(devItem.Tag);
                        bool bOK = SendCheckOTAState(intPtr);
                    }
                }
            }
        }

        private void DoWriteGPRSInfo(DevItemView devItem)
        {
            //获取设置得GPRS信息然后逐个写入
            //经度：普通话拼音：jīng dù ； 英文：longitude ；
            //纬度：普通话拼音：wěi dù ； 英文：latitude ; 
            //string strJson = "{\"reqId\": 40,\"op\": \"W\",\"prop\": {\"loc\" : {\"lng\" : \"120.80235\", \"lat\" : \"31.040786\"} }}";
            string strJson = "{\"reqId\": 40,\"op\": \"W\",\"prop\": {\"locCfg\" : {\"lng\" : \" " + devItem.tb_Set_JingDu.Text + "\", \"lat\" : \"" + devItem.tb_Set_WeiDu.Text + "\"} }}";

            IntPtr intPtr = (IntPtr)(devItem.Tag);// as IntPtr;
            bool bOK = SendMsgNeedJSonBody(strJson, intPtr);

            //写完就读取
            strJson = "{\"reqId\": 40,\"op\": \"R\",\"prop\": [\"loc\"]}";
            bOK = SendMsgNeedJSonBody(strJson, intPtr);
        }

        private void DoSoetDevItemByRssi(WrapPanel lvDevList)
        {
            List<DevItemView> rssiList = new List<DevItemView>();
            //按照升序方式排序
            foreach (DevItemView devItem in lvDevList.Children)
            {
                rssiList.Add(devItem);
            }

            //排序
            if (bUpDown)
            {
                rssiList.Sort
                (
                    delegate(DevItemView item1, DevItemView item2)
                    {
                        //return p1.Id.CompareTo(p2.Id);//升序

                        string strRssi = item1.rssi.Text;
                        if (strRssi == "" || strRssi == " ")
                        {
                            strRssi = "0";
                        }
                        int nRssi1 = GlobalFun.StringToInt32(strRssi);

                        strRssi = item2.rssi.Text;
                        if (strRssi == "" || strRssi == " ")
                        {
                            strRssi = "0";
                        }
                        int nRssi2 = GlobalFun.StringToInt32(strRssi);

                        return nRssi1 - nRssi2;
                    }
                );
            }
            else
            {
                rssiList.Sort
                (
                    delegate(DevItemView item1, DevItemView item2)
                    {
                        //return p1.Id.CompareTo(p2.Id);//升序

                        string strRssi = item1.rssi.Text;
                        if (strRssi == "" || strRssi == " ")
                        {
                            strRssi = "0";
                        }
                        int nRssi1 = GlobalFun.StringToInt32(strRssi);

                        strRssi = item2.rssi.Text;
                        if (strRssi == "" || strRssi == " ")
                        {
                            strRssi = "0";
                        }
                        int nRssi2 = GlobalFun.StringToInt32(strRssi);

                        return nRssi2 - nRssi1;
                    }
                );
            }


            //重新填充界面
            lvDevList.Children.Clear();
            foreach (DevItemView devItem in rssiList)
            {
                lvDevList.Children.Add(devItem);
            }

            //rssiList.Sort((x,y)=> { return x.Id.CompareTo(y.Id); })
        }

        private void DoBeginOTA(DevItemView devItem)
        {
            devItem.ver.Foreground = new SolidColorBrush(Colors.Black);
            devItem.ver.Tag = null;
            //devItem.SetOTAState(DevItemView.byIsOtaing);

            devItem.otaInfo.Text = "请求OTA";
            devItem.otaInfo.Foreground = new SolidColorBrush(Colors.Black);

            //设定开始OTA标志，记录下来开始OTA的时间，后续有信号时实时更新，在系统定时器中判断是否超时
            //devItem.otaInfo.Tag = "IsOTA";
            devItem.otaInfo.Tag = DateTime.Now;//.ToString("yyyy-MM-dd hh:mm:ss fff");
        }

        private bool DoUpdateOTAInfo( WrapPanel lvDevList, string strErr, string strStatus, string strProcess, string strIP, IntPtr connID)
        {
            foreach (DevItemView devItem in lvDevList.Children)
            {
                if (devItem.ip.Text == strIP && devItem.otaInfo.Tag != null)
                {
                    #region
                    devItem.otaInfo.Text = "E-" + strErr + ",S-" + strStatus + ",P-" + strProcess + "%";
                    //更新最后有信号的记录数据
                    devItem.otaInfo.Tag = DateTime.Now;
                    UInt16 uiProcess = GlobalFun.StringToUInt16(strProcess);
                    devItem.otaProgress.Value = uiProcess;
                    devItem.otaProgress.Visibility = System.Windows.Visibility.Visible;

                    //err含义说明：
                    //0, ota no error
                    //1，连接服务器错误
                    //2，malloc错误
                    //3，send错误
                    //4，ota bengin错误
                    //5，ota set SOL_SOCKET错误
                    //6，receive data timeout
                    //7,ota write flash error
                    //8,ota end error
                    //9,ota set boot partition错误

                    if (strErr == "0")
                    {
                        //status:0:等待升级，1:开始下载，2:下载完成，3:正在升级，4:升级成功 , 5:升级失败
                        //if (strStatus == "5")
                        //{
                        //    //升级失败
                        //}
                        switch (strStatus)
                        {
                            case "0"://等待升级
                                {
                                    //OTA成功，取消OTA勾选标志
                                    devItem.otaInfo.Text += " 设备等待OTA";
                                    //等待OTA，则再次发送OTA命令
                                    //devItem.otaInfo.Tag = null;

                                    string strBinFile = tbOTABinFile.Text;
                                    bool bOK = SendOTACmd_Ex(hfsIP.Text, hfsPort.Text, strBinFile, connID);
                                    if (bOK == false)
                                    {
                                        MessageBox.Show("Bin文件 " + strBinFile + " 有问题，请检查！");
                                        return true;
                                    }

                                    devItem.otaProgress.Visibility = System.Windows.Visibility.Collapsed;
                                    devItem.otaInfo.Foreground = new SolidColorBrush(Colors.Blue);
                                }
                                break;
                            case "1"://开始下载
                                break;
                            case "2"://下载完成
                                {
                                    //OTA成功，取消OTA勾选标志
                                    devItem.otaInfo.Text += " OTA下载完毕";
                                    //devItem.otaInfo.Tag = null;
                                    //devItem.otaProgress.Visibility = System.Windows.Visibility.Collapsed;
                                    devItem.otaInfo.Foreground = new SolidColorBrush(Colors.Blue);
                                }
                                break;
                            case "3"://正在升级
                                break;
                            case "4"://升级成功
                                //没有错误
                                if (strProcess == "100")
                                {
                                    //OTA成功，取消OTA勾选标志
                                    devItem.otaInfo.Text += " OTA成功";
                                    devItem.otaInfo.Tag = null;
                                    devItem.otaProgress.Visibility = System.Windows.Visibility.Collapsed;
                                    devItem.otaInfo.Foreground = new SolidColorBrush(Colors.Green);

                                    //主动设置版本???
                                    devItem.ver.Text = tbOTABinFileVer.Text;

                                    IntPtr intPtr = (IntPtr)(devItem.Tag);// as IntPtr;
                                    bool bOK = SendGetDevClasSkuFWVInfoCmd(intPtr);
                                    bOK = SendGetDevClasSkuFWVInfoCmd(intPtr);
                                }
                                break;
                            case "5"://升级失败
                                {
                                    //有错误
                                    devItem.otaInfo.Text += " OTA失败";
                                    devItem.otaInfo.Tag = null;
                                    devItem.otaProgress.Visibility = System.Windows.Visibility.Collapsed;
                                    devItem.otaInfo.Foreground = new SolidColorBrush(Colors.Red);
                                }
                                break;
                            default:
                                break;
                        }
                    }
                    else
                    {
                        //有错误
                        devItem.otaInfo.Text += " OTA失败";
                        devItem.otaInfo.Tag = null;
                        devItem.otaProgress.Visibility = System.Windows.Visibility.Collapsed;
                        devItem.otaInfo.Foreground = new SolidColorBrush(Colors.Red);
                    }
                    #endregion
                    return true;
                }
                else
                {
                    //Not Do Continue
                }
            }
            foreach (DevItemView devItem in lvDevList1.Children)
            {
                if (devItem.ip.Text == strIP && devItem.otaInfo.Tag != null)
                {
                    #region
                    devItem.otaInfo.Text = "E-" + strErr + ",S-" + strStatus + ",P-" + strProcess + "%";
                    //更新最后有信号的记录数据
                    devItem.otaInfo.Tag = DateTime.Now;
                    UInt16 uiProcess = GlobalFun.StringToUInt16(strProcess);
                    devItem.otaProgress.Value = uiProcess;
                    devItem.otaProgress.Visibility = System.Windows.Visibility.Visible;

                    //err含义说明：
                    //0, ota no error
                    //1，连接服务器错误
                    //2，malloc错误
                    //3，send错误
                    //4，ota bengin错误
                    //5，ota set SOL_SOCKET错误
                    //6，receive data timeout
                    //7,ota write flash error
                    //8,ota end error
                    //9,ota set boot partition错误

                    if (strErr == "0")
                    {
                        //status:0:等待升级，1:开始下载，2:下载完成，3:正在升级，4:升级成功 , 5:升级失败
                        //if (strStatus == "5")
                        //{
                        //    //升级失败
                        //}
                        switch (strStatus)
                        {
                            case "0"://等待升级
                                {
                                    //OTA成功，取消OTA勾选标志
                                    devItem.otaInfo.Text += " 设备等待OTA";
                                    //等待OTA，则再次发送OTA命令
                                    //devItem.otaInfo.Tag = null;

                                    string strBinFile = tbOTABinFile.Text;
                                    bool bOK = SendOTACmd_Ex(hfsIP.Text, hfsPort.Text, strBinFile, connID);
                                    if (bOK == false)
                                    {
                                        MessageBox.Show("Bin文件 " + strBinFile + " 有问题，请检查！");
                                        return true;
                                    }

                                    devItem.otaProgress.Visibility = System.Windows.Visibility.Collapsed;
                                    devItem.otaInfo.Foreground = new SolidColorBrush(Colors.Blue);
                                }
                                break;
                            case "1"://开始下载
                                break;
                            case "2"://下载完成
                                {
                                    //OTA成功，取消OTA勾选标志
                                    devItem.otaInfo.Text += " OTA下载完毕";
                                    //devItem.otaInfo.Tag = null;
                                    //devItem.otaProgress.Visibility = System.Windows.Visibility.Collapsed;
                                    devItem.otaInfo.Foreground = new SolidColorBrush(Colors.Blue);
                                }
                                break;
                            case "3"://正在升级
                                break;
                            case "4"://升级成功
                                //没有错误
                                if (strProcess == "100")
                                {
                                    //OTA成功，取消OTA勾选标志
                                    devItem.otaInfo.Text += " OTA成功";
                                    devItem.otaInfo.Tag = null;
                                    devItem.otaProgress.Visibility = System.Windows.Visibility.Collapsed;
                                    devItem.otaInfo.Foreground = new SolidColorBrush(Colors.Green);

                                    //主动设置版本???
                                    devItem.ver.Text = tbOTABinFileVer.Text;

                                    IntPtr intPtr = (IntPtr)(devItem.Tag);// as IntPtr;
                                    bool bOK = SendGetDevClasSkuFWVInfoCmd(intPtr);
                                    bOK = SendGetDevClasSkuFWVInfoCmd(intPtr);
                                }
                                break;
                            case "5"://升级失败
                                {
                                    //有错误
                                    devItem.otaInfo.Text += " OTA失败";
                                    devItem.otaInfo.Tag = null;
                                    devItem.otaProgress.Visibility = System.Windows.Visibility.Collapsed;
                                    devItem.otaInfo.Foreground = new SolidColorBrush(Colors.Red);
                                }
                                break;
                            default:
                                break;
                        }
                    }
                    else
                    {
                        //有错误
                        devItem.otaInfo.Text += " OTA失败";
                        devItem.otaInfo.Tag = null;
                        devItem.otaProgress.Visibility = System.Windows.Visibility.Collapsed;
                        devItem.otaInfo.Foreground = new SolidColorBrush(Colors.Red);
                    }
                    #endregion
                    return true;
                }
                else
                {
                    //Not Do Continue
                }
            }
            foreach (DevItemView devItem in lvDevList2.Children)
            {
                if (devItem.ip.Text == strIP && devItem.otaInfo.Tag != null)
                {
                    #region
                    devItem.otaInfo.Text = "E-" + strErr + ",S-" + strStatus + ",P-" + strProcess + "%";
                    //更新最后有信号的记录数据
                    devItem.otaInfo.Tag = DateTime.Now;
                    UInt16 uiProcess = GlobalFun.StringToUInt16(strProcess);
                    devItem.otaProgress.Value = uiProcess;
                    devItem.otaProgress.Visibility = System.Windows.Visibility.Visible;

                    //err含义说明：
                    //0, ota no error
                    //1，连接服务器错误
                    //2，malloc错误
                    //3，send错误
                    //4，ota bengin错误
                    //5，ota set SOL_SOCKET错误
                    //6，receive data timeout
                    //7,ota write flash error
                    //8,ota end error
                    //9,ota set boot partition错误

                    if (strErr == "0")
                    {
                        //status:0:等待升级，1:开始下载，2:下载完成，3:正在升级，4:升级成功 , 5:升级失败
                        //if (strStatus == "5")
                        //{
                        //    //升级失败
                        //}
                        switch (strStatus)
                        {
                            case "0"://等待升级
                                {
                                    //OTA成功，取消OTA勾选标志
                                    devItem.otaInfo.Text += " 设备等待OTA";
                                    //等待OTA，则再次发送OTA命令
                                    //devItem.otaInfo.Tag = null;

                                    string strBinFile = tbOTABinFile.Text;
                                    bool bOK = SendOTACmd_Ex(hfsIP.Text, hfsPort.Text, strBinFile, connID);
                                    if (bOK == false)
                                    {
                                        MessageBox.Show("Bin文件 " + strBinFile + " 有问题，请检查！");
                                        return true;
                                    }

                                    devItem.otaProgress.Visibility = System.Windows.Visibility.Collapsed;
                                    devItem.otaInfo.Foreground = new SolidColorBrush(Colors.Blue);
                                }
                                break;
                            case "1"://开始下载
                                break;
                            case "2"://下载完成
                                {
                                    //OTA成功，取消OTA勾选标志
                                    devItem.otaInfo.Text += " OTA下载完毕";
                                    //devItem.otaInfo.Tag = null;
                                    //devItem.otaProgress.Visibility = System.Windows.Visibility.Collapsed;
                                    devItem.otaInfo.Foreground = new SolidColorBrush(Colors.Blue);
                                }
                                break;
                            case "3"://正在升级
                                break;
                            case "4"://升级成功
                                //没有错误
                                if (strProcess == "100")
                                {
                                    //OTA成功，取消OTA勾选标志
                                    devItem.otaInfo.Text += " OTA成功";
                                    devItem.otaInfo.Tag = null;
                                    devItem.otaProgress.Visibility = System.Windows.Visibility.Collapsed;
                                    devItem.otaInfo.Foreground = new SolidColorBrush(Colors.Green);

                                    //主动设置版本???
                                    devItem.ver.Text = tbOTABinFileVer.Text;

                                    IntPtr intPtr = (IntPtr)(devItem.Tag);// as IntPtr;
                                    bool bOK = SendGetDevClasSkuFWVInfoCmd(intPtr);
                                    bOK = SendGetDevClasSkuFWVInfoCmd(intPtr);
                                }
                                break;
                            case "5"://升级失败
                                {
                                    //有错误
                                    devItem.otaInfo.Text += " OTA失败";
                                    devItem.otaInfo.Tag = null;
                                    devItem.otaProgress.Visibility = System.Windows.Visibility.Collapsed;
                                    devItem.otaInfo.Foreground = new SolidColorBrush(Colors.Red);
                                }
                                break;
                            default:
                                break;
                        }
                    }
                    else
                    {
                        //有错误
                        devItem.otaInfo.Text += " OTA失败";
                        devItem.otaInfo.Tag = null;
                        devItem.otaProgress.Visibility = System.Windows.Visibility.Collapsed;
                        devItem.otaInfo.Foreground = new SolidColorBrush(Colors.Red);
                    }
                    #endregion
                    return true;
                }
                else
                {
                    //Not Do Continue
                }
            }
            foreach (DevItemView devItem in lvDevList3.Children)
            {
                if (devItem.ip.Text == strIP && devItem.otaInfo.Tag != null)
                {
                    #region
                    devItem.otaInfo.Text = "E-" + strErr + ",S-" + strStatus + ",P-" + strProcess + "%";
                    //更新最后有信号的记录数据
                    devItem.otaInfo.Tag = DateTime.Now;
                    UInt16 uiProcess = GlobalFun.StringToUInt16(strProcess);
                    devItem.otaProgress.Value = uiProcess;
                    devItem.otaProgress.Visibility = System.Windows.Visibility.Visible;

                    //err含义说明：
                    //0, ota no error
                    //1，连接服务器错误
                    //2，malloc错误
                    //3，send错误
                    //4，ota bengin错误
                    //5，ota set SOL_SOCKET错误
                    //6，receive data timeout
                    //7,ota write flash error
                    //8,ota end error
                    //9,ota set boot partition错误

                    if (strErr == "0")
                    {
                        //status:0:等待升级，1:开始下载，2:下载完成，3:正在升级，4:升级成功 , 5:升级失败
                        //if (strStatus == "5")
                        //{
                        //    //升级失败
                        //}
                        switch (strStatus)
                        {
                            case "0"://等待升级
                                {
                                    //OTA成功，取消OTA勾选标志
                                    devItem.otaInfo.Text += " 设备等待OTA";
                                    //等待OTA，则再次发送OTA命令
                                    //devItem.otaInfo.Tag = null;

                                    string strBinFile = tbOTABinFile.Text;
                                    bool bOK = SendOTACmd_Ex(hfsIP.Text, hfsPort.Text, strBinFile, connID);
                                    if (bOK == false)
                                    {
                                        MessageBox.Show("Bin文件 " + strBinFile + " 有问题，请检查！");
                                        return true;
                                    }

                                    devItem.otaProgress.Visibility = System.Windows.Visibility.Collapsed;
                                    devItem.otaInfo.Foreground = new SolidColorBrush(Colors.Blue);
                                }
                                break;
                            case "1"://开始下载
                                break;
                            case "2"://下载完成
                                {
                                    //OTA成功，取消OTA勾选标志
                                    devItem.otaInfo.Text += " OTA下载完毕";
                                    //devItem.otaInfo.Tag = null;
                                    //devItem.otaProgress.Visibility = System.Windows.Visibility.Collapsed;
                                    devItem.otaInfo.Foreground = new SolidColorBrush(Colors.Blue);
                                }
                                break;
                            case "3"://正在升级
                                break;
                            case "4"://升级成功
                                //没有错误
                                if (strProcess == "100")
                                {
                                    //OTA成功，取消OTA勾选标志
                                    devItem.otaInfo.Text += " OTA成功";
                                    devItem.otaInfo.Tag = null;
                                    devItem.otaProgress.Visibility = System.Windows.Visibility.Collapsed;
                                    devItem.otaInfo.Foreground = new SolidColorBrush(Colors.Green);

                                    //主动设置版本???
                                    devItem.ver.Text = tbOTABinFileVer.Text;

                                    IntPtr intPtr = (IntPtr)(devItem.Tag);// as IntPtr;
                                    bool bOK = SendGetDevClasSkuFWVInfoCmd(intPtr);
                                    bOK = SendGetDevClasSkuFWVInfoCmd(intPtr);
                                }
                                break;
                            case "5"://升级失败
                                {
                                    //有错误
                                    devItem.otaInfo.Text += " OTA失败";
                                    devItem.otaInfo.Tag = null;
                                    devItem.otaProgress.Visibility = System.Windows.Visibility.Collapsed;
                                    devItem.otaInfo.Foreground = new SolidColorBrush(Colors.Red);
                                }
                                break;
                            default:
                                break;
                        }
                    }
                    else
                    {
                        //有错误
                        devItem.otaInfo.Text += " OTA失败";
                        devItem.otaInfo.Tag = null;
                        devItem.otaProgress.Visibility = System.Windows.Visibility.Collapsed;
                        devItem.otaInfo.Foreground = new SolidColorBrush(Colors.Red);
                    }
                    #endregion
                    return true;
                }
                else
                {
                    //Not Do Continue
                }
            }
            foreach (DevItemView devItem in lvDevList4.Children)
            {
                if (devItem.ip.Text == strIP && devItem.otaInfo.Tag != null)
                {
                    #region
                    devItem.otaInfo.Text = "E-" + strErr + ",S-" + strStatus + ",P-" + strProcess + "%";
                    //更新最后有信号的记录数据
                    devItem.otaInfo.Tag = DateTime.Now;
                    UInt16 uiProcess = GlobalFun.StringToUInt16(strProcess);
                    devItem.otaProgress.Value = uiProcess;
                    devItem.otaProgress.Visibility = System.Windows.Visibility.Visible;

                    //err含义说明：
                    //0, ota no error
                    //1，连接服务器错误
                    //2，malloc错误
                    //3，send错误
                    //4，ota bengin错误
                    //5，ota set SOL_SOCKET错误
                    //6，receive data timeout
                    //7,ota write flash error
                    //8,ota end error
                    //9,ota set boot partition错误

                    if (strErr == "0")
                    {
                        //status:0:等待升级，1:开始下载，2:下载完成，3:正在升级，4:升级成功 , 5:升级失败
                        //if (strStatus == "5")
                        //{
                        //    //升级失败
                        //}
                        switch (strStatus)
                        {
                            case "0"://等待升级
                                {
                                    //OTA成功，取消OTA勾选标志
                                    devItem.otaInfo.Text += " 设备等待OTA";
                                    //等待OTA，则再次发送OTA命令
                                    //devItem.otaInfo.Tag = null;

                                    string strBinFile = tbOTABinFile.Text;
                                    bool bOK = SendOTACmd_Ex(hfsIP.Text, hfsPort.Text, strBinFile, connID);
                                    if (bOK == false)
                                    {
                                        MessageBox.Show("Bin文件 " + strBinFile + " 有问题，请检查！");
                                        return true;
                                    }

                                    devItem.otaProgress.Visibility = System.Windows.Visibility.Collapsed;
                                    devItem.otaInfo.Foreground = new SolidColorBrush(Colors.Blue);
                                }
                                break;
                            case "1"://开始下载
                                break;
                            case "2"://下载完成
                                {
                                    //OTA成功，取消OTA勾选标志
                                    devItem.otaInfo.Text += " OTA下载完毕";
                                    //devItem.otaInfo.Tag = null;
                                    //devItem.otaProgress.Visibility = System.Windows.Visibility.Collapsed;
                                    devItem.otaInfo.Foreground = new SolidColorBrush(Colors.Blue);
                                }
                                break;
                            case "3"://正在升级
                                break;
                            case "4"://升级成功
                                //没有错误
                                if (strProcess == "100")
                                {
                                    //OTA成功，取消OTA勾选标志
                                    devItem.otaInfo.Text += " OTA成功";
                                    devItem.otaInfo.Tag = null;
                                    devItem.otaProgress.Visibility = System.Windows.Visibility.Collapsed;
                                    devItem.otaInfo.Foreground = new SolidColorBrush(Colors.Green);

                                    //主动设置版本???
                                    devItem.ver.Text = tbOTABinFileVer.Text;

                                    IntPtr intPtr = (IntPtr)(devItem.Tag);// as IntPtr;
                                    bool bOK = SendGetDevClasSkuFWVInfoCmd(intPtr);
                                    bOK = SendGetDevClasSkuFWVInfoCmd(intPtr);
                                }
                                break;
                            case "5"://升级失败
                                {
                                    //有错误
                                    devItem.otaInfo.Text += " OTA失败";
                                    devItem.otaInfo.Tag = null;
                                    devItem.otaProgress.Visibility = System.Windows.Visibility.Collapsed;
                                    devItem.otaInfo.Foreground = new SolidColorBrush(Colors.Red);
                                }
                                break;
                            default:
                                break;
                        }
                    }
                    else
                    {
                        //有错误
                        devItem.otaInfo.Text += " OTA失败";
                        devItem.otaInfo.Tag = null;
                        devItem.otaProgress.Visibility = System.Windows.Visibility.Collapsed;
                        devItem.otaInfo.Foreground = new SolidColorBrush(Colors.Red);
                    }
                    #endregion
                    return true;
                }
                else
                {
                    //Not Do Continue
                }
            }
            return false;
        }

        private bool DoUpdateVerInfo(WrapPanel lvDevList, string strIP, string strVerInfo, string strSkuInfo,string strClasInfo)
        {
            foreach (DevItemView devItem in lvDevList.Children)
            {
                if (devItem.ip.Text == strIP)
                {
                    devItem.ver.Text = strVerInfo + "|" + strClasInfo + "|" + strSkuInfo + "(???)";// +" [" + strJLocInfo + "," + strWLocInfo + "]";
                    return true;
                }
                else
                {
                }
            }

            return false;
        }
    }
}
